package com.wash.shoes.page;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 *
 */
public class PageFactory {

    public static <T> Page<T> defaultPage() {

        HttpServletRequest request = HttpContext.getRequest();
        assert request != null;
        String pageNo = request.getParameter("pageNo");
        if (!StringUtils.isNumeric(pageNo)) {
            //          throw new PageNoException("请添加分页参数 pageNo 例如 [?pageNo=1]");
            pageNo = "1";
        }
        int page = Integer.parseInt(pageNo);

        String pageSize = request.getParameter("pageSize");
        if (pageSize != null) {
            return new Page<>(page, Integer.parseInt(pageSize));
        } else {
            return new Page<>(page, 10);
        }
    }
}
